<?php include "htmlBase/header.php"; ?>

<?php
require_once "Entidades/EntidadeBase.php";
require_once "Entidades/Responsavel.php";
$responsavel = new Responsavel();
$responsavel->Converter($_POST);

require_once "ViewBase.php";

$where = Array();

if ($responsavel->id_Cras != 0)
    $where[] = "Id_Cras = " . $responsavel->formatarCampo($responsavel->id_Cras);

if ($responsavel->Nome != "")
{
    $where[] = "Nome like " . $responsavel->formatarCampo($responsavel->Nome . "%");
}

$Entidades = MontarHeadPHP("Responsavel", isset($_GET["Filtro"]), implode(" and ", $where));
MontarHeadScript("Responsavel", "Cadastro", "Painel");

include_once 'Controles/ComboBox.php';
?>

<div class="page">
    <div class="page-header">
        <div class="page-header-content">
            <h1>Responsável <small>(Pesquisar)</small></h1>
        </div>
        <div class="progress-bar" align="rigth">
            <div class="bar bg-color-blue" style="width: 75%"></div>
        </div>
    </div>
    <br/>
    <div class="page">
        <div class="page-region">
            <div class="page-region-content">
                <form action="?Filtro=0" method="POST" id="frmFiltro">
                    <div>
                        <div class="row">
                            <div class="span7 input-control" style="float: left">
                                <h4>Nome</h4>
                                <input type="text" class="with-helper" placeholder="Nome" name="Nome" value="<?php echo $responsavel->Nome; ?>" maxlength="60"/>
                            </div>

                            <div class="span4 input-control" style="float: left; margin-left: 5px;">
                                <h4>Cras</h4>
                                <?php ComboBox("Cras", "id_Cras", $responsavel->id_Cras, true); ?>
                            </div>

                            <div class="span1 input-control" style="float: right;" onclick="Filtrar()">
                                <h1 class="icon-search" style="cursor: pointer"/>
                            </div>
                        </div>
                    </div>
                </form>

                <table class="hovered bordered">
                    <th></th>
                    <th>Nome</th>
                    <th>Cras</th>
                    <th>Endereço</th>
                    <th>Telefone</th>

                    <?php
                    if ($Entidades == null)
                    {
                        ?>
                        <tr>
                            <td colspan="8">
                                <h3 style="text-align:center">Sem Resultado</h3>
                            </td>
                        </tr>
                        <?php
                    } else
                    {
                        foreach ($Entidades as $Responsavel)
                        {
                            ?>
                            <tr onclick="Selecionar(<?php echo $Responsavel->Id; ?>)">
                                <td width="1"><input type="radio" name="RadioId" Id="<?php echo $Responsavel->Id; ?>" value="<?php echo $Responsavel->Id; ?>"></td>
                                <td><?php echo $Responsavel->Nome; ?></td>
                                <td><?php echo $Responsavel->getCras()->Nome; ?></td>
                                <td><?php echo $Responsavel->getEnderecoCompleto(); ?></td>
                                <td><?php echo $Responsavel->Telefone; ?></td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </table>

                <div class="input-control" style="margin-left: auto; margin-right: auto;">
                    <button class="standart default" onclick="Novo()">Novo</button>
                    <button class="standart" onclick="Alterar()">Alterar</button>
                    <button class="standart" onclick="Excluir()">Excluir</button>
                    <a href="Index.php" class="button standart bg-color-lighten" style="float: right">Voltar</a>
                </div>

            </div>
        </div>
    </div>

</div>

<script>
    function Filtrar()
    {
        var form = document.getElementById("frmFiltro");
        form.submit();
    }
</script>

<?php include "htmlBase/footer.php"; ?>